package com.ssm.zyn.action;

import com.ssm.zyn.eo.RoleLimitEOpage;
import com.ssm.zyn.model.RoleLimit;
import com.ssm.zyn.service.RoleLimitService;
import com.ssm.zyn.tool.ResponseMessage;
import com.ssm.zyn.tool.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 对外提供数据服务接口
 */
@Api(tags="RoleLimit")
@RestController
@CrossOrigin
public class RoleLimitController {
    @Autowired
    private RoleLimitService roleLimitService;
    @ApiOperation(value = "人员权限信息添加方法")
    @RequestMapping(value="/addRoleLimit",method = RequestMethod.GET)
    public ResponseMessage addRoleLimit(RoleLimit roleLimit){
        int IsAdd=0;
        //传入数据的判断
        //（1）实体对象不能为空
        if(roleLimit!=null){

                //(2)添加数据
                IsAdd=roleLimitService.AddRoleLimit(roleLimit);
                if(IsAdd==1){
                    return Result.success("保存成功");
                }else {
                    return Result.error("保存失败");
                }
            }

        return Result.error("保存失败");
    }
    @ApiOperation(value = "人员权限信息修改方法")
    @RequestMapping(value="/updateRoleLimit",method = RequestMethod.GET)
    public ResponseMessage updateRoleLimit(RoleLimit roleLimit){
        int isUpdate=0;
        //传入的参数不能为空
        if(roleLimit!=null){
            //参数当中主键不能为0

            if (roleLimit.getRlid()!=0){
                isUpdate=roleLimitService.UpdateRoleLimit(roleLimit);
                if(isUpdate==1){

                    return Result.success("更新成功");
                }else {
                    return Result.error("更新失败");
                }
            }
        }
        return  Result.error("传入参数不正确");
    }
    @ApiOperation(value = "人员权限信息删除方法")
    @RequestMapping(value="/delRoleLimit",method = RequestMethod.GET)
    public ResponseMessage deRoleLimit(int rlid){
        if (rlid!=0){
            int delInt=0;
            delInt=roleLimitService.DeleteRoleLimit(rlid);
            if(delInt>0){
                return Result.success("删除成功");
            }
        }
            return Result.error("删除的主键不能为0,请重新输入");

    }
    @ApiOperation(value = "根据条件获取人员权限信息")
    @RequestMapping(value = "/getRoleLimitAll",produces = "application/json;charset=utf-8",method = RequestMethod.POST)
    public ResponseMessage getRoleLimitAll(@RequestBody RoleLimitEOpage roleLimitEOpage){
        Map<String, List> map=new HashMap<>();
        List<RoleLimitEOpage> listRolelimit=roleLimitService.getWhereAll(roleLimitEOpage);
        map.put("list",listRolelimit);
        return Result.success("200",map);
    }
}
